import 'activity_data.dart';
import 'user_comment.dart';

/// 用户过滤内容响应模型
/// 对应API接口：/users/filtered_content/
class UserFilteredContentResponse {
  final String status;
  final String? message;
  final FilteredUserInfo? user;
  final int? friendCount;
  final List<ActivityData>? activities;
  final List<UserComment>? comments;

  UserFilteredContentResponse({
    required this.status,
    this.message,
    this.user,
    this.friendCount,
    this.activities,
    this.comments,
  });

  bool get isSuccess => status == 'success';

  factory UserFilteredContentResponse.fromJson(Map<String, dynamic> json) {
    return UserFilteredContentResponse(
      status: json['status'] ?? 'error',
      message: json['message'],
      user: json['user'] != null ? FilteredUserInfo.fromJson(json['user']) : null,
      friendCount: json['friend_count'],
      activities: json['activities'] != null 
          ? (json['activities'] as List).map((e) => ActivityData.fromJson(e)).toList()
          : null,
      comments: json['comments'] != null
          ? (json['comments'] as List).map((e) => UserComment.fromJson(e)).toList()
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'status': status,
      if (message != null) 'message': message,
      if (user != null) 'user': user!.toJson(),
      if (friendCount != null) 'friend_count': friendCount,
      if (activities != null) 'activities': activities!.map((e) => e.toJson()).toList(),
      if (comments != null) 'comments': comments!.map((e) => e.toJson()).toList(),
    };
  }
}

/// 过滤的用户信息模型
/// 对应API响应中的user字段
class FilteredUserInfo {
  final int userid;
  final String? userPhone;
  final String? userEmail;
  final int? userCode;
  final String username;
  final String? userAvatarUrl;
  final Map<String, dynamic>? userData;
  final int? userAge;
  final String? userGender;
  final String? userSignature;
  final List<String>? userTags;
  final int? userLikes;
  final int? userFollowers;
  final int? userPoints;
  final List<String>? userHobbies;
  final String? userCity;
  final List<String>? userImgUrls;
  final String? userFrequentPlaces;
  final String? userBirthday;
  final int? userLevel;
  final String? status;
  final Map<String, dynamic>? extraData;
  final String? createdAt;
  final String? lastLogin;
  final String? updatedAt;

  FilteredUserInfo({
    required this.userid,
    this.userPhone,
    this.userEmail,
    this.userCode,
    required this.username,
    this.userAvatarUrl,
    this.userData,
    this.userAge,
    this.userGender,
    this.userSignature,
    this.userTags,
    this.userLikes,
    this.userFollowers,
    this.userPoints,
    this.userHobbies,
    this.userCity,
    this.userImgUrls,
    this.userFrequentPlaces,
    this.userBirthday,
    this.userLevel,
    this.status,
    this.extraData,
    this.createdAt,
    this.lastLogin,
    this.updatedAt,
  });

  factory FilteredUserInfo.fromJson(Map<String, dynamic> json) {
    return FilteredUserInfo(
      userid: json['userid'] ?? 0,
      userPhone: json['userPhone'],
      userEmail: json['userEmail'],
      userCode: json['userCode'],
      username: json['username'] ?? '',
      userAvatarUrl: json['userAvatarUrl'],
      userData: json['userData'] is Map ? Map<String, dynamic>.from(json['userData']) : null,
      userAge: json['userAge'],
      userGender: json['userGender'],
      userSignature: json['userSignature'],
      userTags: json['userTags'] is List ? List<String>.from(json['userTags']) : null,
      userLikes: json['userLikes'],
      userFollowers: json['userFollowers'],
      userPoints: json['userPoints'],
      userHobbies: json['userHobbies'] is List ? List<String>.from(json['userHobbies']) : null,
      userCity: json['userCity'],
      userImgUrls: json['userImgUrls'] is List ? List<String>.from(json['userImgUrls']) : null,
      userFrequentPlaces: json['userFrequentPlaces'],
      userBirthday: json['userBirthday'],
      userLevel: json['userLevel'],
      status: json['status'],
      extraData: json['extraData'] is Map ? Map<String, dynamic>.from(json['extraData']) : null,
      createdAt: json['created_at'],
      lastLogin: json['last_login'],
      updatedAt: json['updated_at'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'userid': userid,
      if (userPhone != null) 'userPhone': userPhone,
      if (userEmail != null) 'userEmail': userEmail,
      if (userCode != null) 'userCode': userCode,
      'username': username,
      if (userAvatarUrl != null) 'userAvatarUrl': userAvatarUrl,
      if (userData != null) 'userData': userData,
      if (userAge != null) 'userAge': userAge,
      if (userGender != null) 'userGender': userGender,
      if (userSignature != null) 'userSignature': userSignature,
      if (userTags != null) 'userTags': userTags,
      if (userLikes != null) 'userLikes': userLikes,
      if (userFollowers != null) 'userFollowers': userFollowers,
      if (userPoints != null) 'userPoints': userPoints,
      if (userHobbies != null) 'userHobbies': userHobbies,
      if (userCity != null) 'userCity': userCity,
      if (userImgUrls != null) 'userImgUrls': userImgUrls,
      if (userFrequentPlaces != null) 'userFrequentPlaces': userFrequentPlaces,
      if (userBirthday != null) 'userBirthday': userBirthday,
      if (userLevel != null) 'userLevel': userLevel,
      if (status != null) 'status': status,
      if (extraData != null) 'extraData': extraData,
      if (createdAt != null) 'created_at': createdAt,
      if (lastLogin != null) 'last_login': lastLogin,
      if (updatedAt != null) 'updated_at': updatedAt,
    };
  }
}
